﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;

namespace Zocono.WCS.Domain.PlcBytesObject
{
    /// <summary>
    /// 成品库分档组盘位PLC读DB报文
    /// </summary>
    public class PlanarBatteryPlcActionBO : BytesObjectBase
    {

        /// <summary>
        /// 托盘码
        /// </summary>
        public string PalletBarcode { get; set; }

        #region 电池信息

        /// <summary>
        /// 电池集合
        /// </summary>
        public List<BatteryItemDto> BatteryItems { get; set; }

        #endregion


        public override void Serialize(long plcConnectionID, long plcReadDbID, int bytesIndex, int bytesLength, int objectIndex, int objectLength, string objectType, string ScEquipmentCode, byte[] bytes)
        {
            PlcConnectionID = plcConnectionID;
            PlcReadDbID = plcReadDbID;
            BytesIndex = bytesIndex;
            BytesLength = bytesLength;
            ObjectIndex = objectIndex;
            ObjectLength = objectLength;
            ObjectType = objectType;


            EquipmentCode = HelperByte.GetDIntAt(bytes, 0).ToString();
            int lengthPall = HelperByte.GetSIntAt(bytes, 5);
            PalletBarcode = HelperByte.GetCharsAt(bytes, 6, lengthPall).Trim();

            BatteryItems = new List<BatteryItemDto>();
            //电池信息集合 测试OK使用此方案
            for (int i = 0; i < (bytes.Length - 24) / 34; i++)
            {
                BatteryItemDto item = new BatteryItemDto();
                item.BatteryIndex = HelperByte.GetIntAt(bytes, 24 + 34 * i);
                int lengthItem = HelperByte.GetSIntAt(bytes, 24 + 3 + 34 * i);
                item.BatteryCode = HelperByte.GetCharsAt(bytes, 24 + 4 + 34 * i, lengthItem).Trim();
                BatteryItems.Add(item);
            }


        }

    }
}
